package com.galo.service.service;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 智能空调
 * @Auther: lxlin
 * @Date: 2018/11/15 16:53
 * @Description:
 */
@Component
public class AirConditionerService {

    @Autowired
    private MqttGateway gateway;

    /**
     * 智能空调开关控制
     * @param devsn 设备标识
     * @param sta 状态
     */
    @Async("taskExecutor")
    public void control(String devsn,String sta){
        Map map = new LinkedHashMap();
        map.put("type","air-cond");
        map.put("action","set");
        map.put("devsn",devsn);
        map.put("sta",sta);
        gateway.sendToMqtt("galo/device/control/air",1,JSON.toJSONString(map));
    }

    /**
     * 切换空调品牌接口
     * @param devsn 空调设备编号
     * @param brand 品牌编号
     */
    @Async("taskExecutor")
    public void brand(String devsn,int brand)
    {
        Map map = new LinkedHashMap();
        map.put("type","air-cond");
        map.put("action","set");
        map.put("devsn",devsn);
        map.put("brand",brand);
        gateway.sendToMqtt("galo/device/control/air",1,JSON.toJSONString(map));
    }

    /**
     * 空调温度调节接口
     * @param devsn 空调设备编号
     * @param tmp 目标温度
     */
    @Async("taskExecutor")
    public void tempering(String devsn,int tmp)
    {
        Map map = new LinkedHashMap();
        map.put("type","air-cond");
        map.put("action","set");
        map.put("devsn",devsn);
        map.put("tmp",tmp);
        gateway.sendToMqtt("galo/device/control/air",1,JSON.toJSONString(map));
    }

    /**
     * 空调模式切换接口
     * @param devsn 空调设备编号
     * @param mode 空调模式
     */
    @Async("taskExecutor")
    public void mode(String devsn,String mode)
    {
        Map map = new LinkedHashMap();
        map.put("type","air-cond");
        map.put("action","set");
        map.put("devsn",devsn);
        map.put("mode",mode);
        gateway.sendToMqtt("galo/device/control/air",1,JSON.toJSONString(map));
    }
}
